package org.example.ch06.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName RabbitConfig
 * @Description TODO
 * @Author Kx
 * @Date 2025/10/14 10:56
 * @Version 1.0
 */
@Configuration
public class RabbitConfig {
    /**
     * @author: kx
     * @date: 2025/10/14 10:58
     * @return org.springframework.amqp.core.Exchange
     * @description: 创建交换机
    */
    @Bean
    public Exchange exchange() {
        return new DirectExchange("test.exchange");
    }

    /**
     * @author: kx
     * @date: 2025/10/14 10:59
     * @return org.springframework.amqp.core.Queue
     * @description: 创建队列
    */
    @Bean
    public Queue queue() {
        // 非持久化队列
        return new Queue("test.queue", false);
    }

    /**
     * @author: kx
     * @date: 2025/10/14 11:01
     * @return org.springframework.amqp.core.Binding
     * @description: 绑定队列和交换机
    */
    @Bean
    public Binding binding() {
        return BindingBuilder.bind(queue())
                .to(exchange())
                .with("key.test")
                .noargs();
    }
}
